// pages/index/platform_activities/add_activeites/add_activeites.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        multiArray: [],
        multiIndex: 0,
        timeValue: "请选择时间",
        isChooseTime:false,
        newDate: '',
        region: [],
        address: '',
        regions: ''

    },


    bindMultiPickerChange: function(e) {
        console.log(e);
        this.setData({
            timeValue: e.detail.value,
            isChooseTime:true
        })
    },
        // 选择省区
    bindRegionChange: function(e) {
      let  region = e.detail.value;
      let regions = region[0]+region[1]+region[2];
      console.log(regions);

        this.setData({
            region: e.detail.value,
            regions:　regions

        })
    },
    tapbind:function(e) {
        console.log(e.detail.value);
        this.setData({
            address: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let newDate = app.util.formatTime(new Date(),'yyyy-MM-dd');
        this.setData({
            newDate: newDate
        })
    },
    submitRelease:function(){
        let _this = this,
            userInfo = app.globalData.userInfo;
        if (_this.data.regions == '' || _this.data.address =="") {
            wx.showToast({
                title:'请填写完整地址',
                icon:'none'
            })
            return
        }
        if (this.data.isChooseTime) {
            app.util.ajax({
                url: 'Platform/add',
                data: {
                    user_id:userInfo.user_id,
                    state: userInfo.state,
                    end_time:_this.data.timeValue,
                    address: _this.data.regions + _this.data.address
                },
                success: function(res) {
                    if (res.state) {
                        wx.showToast({
                            title: res.info,
                            icon: 'success',
                            duration: 2000
                        })
                        setTimeout(function(){
                            wx.navigateBack({
                                delta:1
                            })
                        },2000);
                    }
                }
            })
        }else{
            wx.showToast({
                title:"请选择结束时间",
                icon:'none'
            })
        }
            
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})